


# 铜币 银币 金币
# 100铜币=1银币 100银币=1金币
#
# 1英镑=20先令=240便士

Units = {
    "copper_coin": {
        "name": "铜币",
        "rate": 1
    },
    "silver_coin": {
        "name": "银币",
        "rate": 100
    },
    "gold_coin": {
        "name": "金币",
        "rate": 10000
    },
    "gold_bar": {
        "name": "金条",
        "rate": 500000
    },
    "pound": {
        "name": "英镑",
        "rate": 4800
    },
    "shilling": {
        "name": "先令",
        "rate": 240
    },
    "pence": {
        "name": "便士",
        "rate": 20
    }
}

def convert_to_int_if_necessary(value):
    if value == int(value):  # 检查小数部分是否为0
        return int(value)    # 如果小数部分为0，则转换为整数
    else:
        return value  

def printFormatRet(fr):
    for unit in fr:
        print(f"{str(convert_to_int_if_necessary(fr[unit]))}{Units[unit]['name']}")

def formatUnit(value, unit) :
    if unit in Units:
        base = value * Units[unit]["rate"]
        ret = {}
        for u in Units:
           ret[u] = round(base / Units[u]["rate"],8)
        return ret

ret = formatUnit(2, "pence")
printFormatRet(ret)




